﻿
@{
    ViewBag.Title = "拼柜管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var warehouses = ViewBag.Warehouses as List<IOA.MES.DataAccess.VModel.VUserWarehouse>;
}

@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WarehouseName">拼柜仓库：</label>
                        <div class="layui-input-inline">
                            <select id="selWarehouses" lay-filter="selWarehouses" lay-search="">
                                <option value="">全部仓库</option>
                                @foreach (var item in warehouses)
                                {
                                    <option value="@item.WarehouseCode">@item.WarehouseName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.OrderNo">订单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtOrderNo" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkorderNo">工单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtWorkOrderNo" placeholder="请输入工单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CabinetNo">柜号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtCabinetNo" placeholder="请输入柜号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CreateTime">日期：</label>
                        <div class="layui-input-inline" style="width: 310px;">
                            <input type="text" id="txtRangeTime" placeholder="请选择拼柜时间" value="@(DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss") + " 至 " + DateTime.Today.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"))" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#txtRangeTime'
                    , type: 'datetime'
                    , range: '至'
                });
                var options = {
                    elem: '#table'
                    , url: '/Warehouse/QueryCabinets'
                    , method: "post"
                    , where: { warehouseCode: "", orderNo: "", workOrderNo: "", cabinetNo:"", startTime: "@DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss")", endTime: "@DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss")" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', minWidth: 80, type: "numbers", fixed: 'left' }
                        , { field: 'CabinetNo', title: '柜号', minWidth:150, fixed: 'left' }
                        , { field: 'OrderNo', title: '订单号', minWidth: 150 }
                        , { field: 'WorkOrderNo', title: '工单号', minWidth: 200 }
                        , { field: 'QLevel', title: '等级' }
                        , { field: 'ComponentColor', title: '颜色' }
                        , { field: 'IVPowerLevel', title: '功率' }
                        , { field: 'IVCurrentLevel', title: '档位' }
                        , { field: 'NameplateModel', title: '铭牌型号', minWidth: 150 }
                        , { field: 'CNCreateBy', title: '拼柜人', minWidth: 100 }
                        , { field: 'CreateTimeStr', title: '拼柜时间', minWidth: 150 }
                        , { field: 'CNPackStatus', minWidth: 120, title: '拼柜状态' }
                        , {
                            title: '操作', fixed: 'right', minWidth: 120, templet: function (d) {
                                var str = d.Status == 2 ? '' : (d.Status == 0 ? '<button class="layui-btn layui-btn-sm" onclick="continueCabinet(\'' + d.CabinetNo + '\')"><i class="layui-icon">&#xe642;</i>继续拼柜</button>'
                                    : '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="cabinetDetail(\'' + d.CabinetNo + '\')"><i class="layui-icon">&#xe615;</i>拼柜明细</button>');
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.warehouseCode = $("#selWarehouses").val();
                    options.where.orderNo = $("#txtOrderNo").val();
                    options.where.workOrderNo = $("#txtWorkOrderNo").val();
                    options.where.cabinetNo = $("#txtCabinetNo").val();
                    var rangeTime = $("#txtRangeTime").val().trim() == '' ? new Array() : $("#txtRangeTime").val().trim().split(' 至 ');
                    options.where.startTime = rangeTime.length <= 0 ? null : rangeTime[0];
                    options.where.endTime = rangeTime.length <= 0 ? null : rangeTime[1];

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function continueCabinet(cabinetNo) {
            parent.layui.index.openTabsPage("/Warehouse/CabinetEdit?cabinetNo=" + cabinetNo, "拼柜详情(" + cabinetNo + ")");
        }

        function cabinetDetail(cabinetNo) {
            parent.layui.index.openTabsPage("/Warehouse/CabinetDetail?cabinetNo=" + cabinetNo, "拼柜详情(" + cabinetNo + ")");
        }
    </script>
}
